USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Images-Insert]    Script Date: [[20120914064955]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064955]]
-- Description:	Insert record into table [dbo].[Images]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Images-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Images-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Images-Insert]
	/*@Image_ID uniqueidentifier =Null  , 
	@Image_Default varbinary =Null  , 
	@Image_Data varbinary =Null  , 
	@Image_Description varchar(100) =Null  , 
	@Image_TimeStamp timestamp =Null OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Images](/*[Image_ID], [Image_Default], [Image_Data], [Image_Description]*/)
	VALUES     (/*@Image_ID, @Image_Default, @Image_Data, @Image_Description*/)

	/*SELECT @Image_TimeStamp = [Image_TimeStamp]
    FROM [dbo].[Images]
    WHERE  ( [Image_ID] =@Image_ID )
	AND  ( [Image_Default] =@Image_Default )
	AND  ( [Image_Data] =@Image_Data )
	AND  ( [Image_Description] =@Image_Description )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Images-update]    Script Date: [[20120914064955]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064955]]
-- Description:	Update record in table [dbo].[Images]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Images-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Images-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Images-update]
	/*@Image_ID uniqueidentifier =Null  , 
	@Image_Default varbinary =Null  , 
	@Image_Data varbinary =Null  , 
	@Image_Description varchar(100) =Null  , 
	@Image_TimeStamp timestamp =Null OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/*SELECT @OldTimeStamp = [Image_TimeStamp]
    FROM [dbo].[Images]
    	WHERE ([Image_ID] = @Image_ID)

    IF  @OldTimeStamp = @Image_TimeStamp
    BEGIN*/
		Update [dbo].[Images] SET 
		/*[Image_ID] =@Image_ID, 
		[Image_Default] =@Image_Default, 
		[Image_Data] =@Image_Data, 
		[Image_Description] =@Image_Description*/
		/*WHERE ([Image_ID] = @Image_ID)*/
	/*END*/

	/*SELECT @Image_TimeStamp = [Image_TimeStamp]
    FROM [dbo].[Images]
	WHERE ([Image_ID] = @Image_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Images-Insert-Update]    Script Date: [[20120914064955]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064955]]
-- Description:	Insert OR Update record into table [dbo].[Images]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Images-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Images-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Images-Insert-Update]
	/*@Image_ID uniqueidentifier =Null  , 
	@Image_Default varbinary =Null  , 
	@Image_Data varbinary =Null  , 
	@Image_Description varchar(100) =Null  , 
	@Image_TimeStamp timestamp =Null OUTPUT , 
	@Inserted bit OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Images] 
					/*WHERE ([Image_ID] = @Image_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Images](/*[Image_ID], [Image_Default], [Image_Data], [Image_Description]*/)
		VALUES     (/*@Image_ID, @Image_Default, @Image_Data, @Image_Description*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/*SELECT @OldTimeStamp = [Image_TimeStamp]
		FROM [dbo].[Images]
    	WHERE ([Image_ID] = @Image_ID)

		IF  @OldTimeStamp = @Image_TimeStamp
		BEGIN*/
			Update [dbo].[Images] SET 
			/*[Image_ID] =@Image_ID, 
			[Image_Default] =@Image_Default, 
			[Image_Data] =@Image_Data, 
			[Image_Description] =@Image_Description*/
			/*WHERE ([Image_ID] = @Image_ID)*/
		/*END*/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Image_TimeStamp = [Image_TimeStamp]
    FROM [dbo].[Images]
	WHERE ([Image_ID] = @Image_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Images-Delete]    Script Date: [[20120914064955]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064955]]
-- Description:	delete records from table [dbo].[Images] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Images-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Images-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Images-Delete]
	/*@Image_ID uniqueidentifier =null  , 
	@Image_Default varbinary =null  , 
	@Image_Data varbinary =null  , 
	@Image_Description varchar(100) =null  , 
	@Image_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Images]
	WHERE /*( [Image_ID] = ISNULL(@Image_ID, [Image_ID]) )
	AND ( [Image_Default] = ISNULL(@Image_Default, [Image_Default]) )
	AND ( [Image_Data] = ISNULL(@Image_Data, [Image_Data]) )
	AND ( [Image_Description] like ISNULL(@Image_Description, [Image_Description]) )
	AND ( [Image_TimeStamp] = ISNULL(@Image_TimeStamp, [Image_TimeStamp]) )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Images-Select]    Script Date: [[20120914064955]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064955]]
-- Description:	select records from table [dbo].[Images] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Images-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Images-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Images-Select]
	/*@Image_ID uniqueidentifier =null  , 
	@Image_Default varbinary =null  , 
	@Image_Data varbinary =null  , 
	@Image_Description varchar(100) =null  , 
	@Image_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Images]
	WHERE /*( [Image_ID] = ISNULL(@Image_ID, [Image_ID]) )
	AND ( [Image_Default] = ISNULL(@Image_Default, [Image_Default]) )
	AND ( [Image_Data] = ISNULL(@Image_Data, [Image_Data]) )
	AND ( [Image_Description] like ISNULL(@Image_Description, [Image_Description]) )
	AND ( [Image_TimeStamp] = ISNULL(@Image_TimeStamp, [Image_TimeStamp]) )*/
END
GO
-- =============================================
